import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '../views/Home.vue';
import Login from '../views/Login.vue';
import Test from '../views/right/count/Test.vue';
// import right from '../views/homecommmen/right.vue'
import face from '../views/right/face.vue';
import stu from '../views/right/count/stu.vue';

import Renshiguanli from '../views/right/Personnel/Renshiguanli.vue';
import Family from '../views/right/Personnel/family.vue';

import xiangxixingxi from '../views/right/Personnel//xiangxixingxi.vue';
import jiashu from '../views/right/Personnel/jiashu.vue';
import jianli from '../views/right/Personnel/jianli.vue';

import Levelcode from '../views/right/Public Health/Levelcode.vue';
import Medicalmoney from '../views/right/Public Health/Medicalmoney.vue';
import Bill from '../views/right/Outpatient Clinic/zhiyuan/Bill.vue';
import Medical from '../views/right/Outpatient Clinic/zhiyuan/Medical.vue';
import Toptable from '../views/right/Outpatient Clinic/zhiyuan/Top-table.vue';
import Topup from '../views/right/Outpatient Clinic/zhiyuan/Top-up.vue';
import PatientsOther from '../views/right/Outpatient Clinic/zhang/PatientsOther.vue';
import PatientsOur from '../views/right/Outpatient Clinic/zhang/PatientsOur.vue';
import RegistrationDetials from '../views/right/Outpatient Clinic/zhang/RegistrationDetials.vue';
import Tongji from '../views/right/Outpatient Clinic/zhang/Tongji.vue';
import Doctorviews from '../views/right/Outpatient Clinic/fan/Doctorviews.vue';
import Jianchaitems from '../views/right/Outpatient Clinic/fan/Jianchaitems.vue';
import Menzhenkemu from '../views/right/Outpatient Clinic/fan/Menzhenkemu.vue';
import Shujutongji from '../views/right/Outpatient Clinic/fan/Shujutongji.vue';
import Searchziliao from '../views/right/Outpatient Clinic/fan/Searchziliao.vue';
import bingan from '../views/right/Medical records/bingan.vue';
import bingli from '../views/right/Medical records/bingli.vue';
import guojijibing from '../views/right/Medical records/guojijibing.vue';
import shoushu from '../views/right/Medical records/shoushu.vue';

import Bingantongji from '../views/right/Medical records/tongji.vue';
import BinganXq from '../views/right/Medical records/BinganXq.vue';
import UpdataBingAn from '../views/right/Medical records/UpdataBingAn.vue';

// import tongji from '../views/right/Medical records/tongji.vue';
import countdata from '../views/right/count/countdata.vue';

//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push;
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

Vue.use(VueRouter);

const routes = [
  {
    path: '/',
    name: 'login',
    components: {
      default: Login,
    },
    meta: {
      isAuthenticated: true,
    },
  },
  {
    path: '/home',
    name: 'home',
    redirect: { name: 'face' },
    components: {
      default: Home,
    },
    meta: {
      title: '医疗系统',
      isAuthenticated: false,
      isLogin: true,
    },
    children: [
      {
        path: '',
        name: 'face',
        components: {
          // test:Test,
          right: face,
        },
        meta: {
          title: '首页',
          isAuthenticated: false,
        },
      },
      {
        path: 'test',
        name: 'test',
        components: {
          right: Test,
        },
        meta: { title: '开药', isAuthenticated: false },
      },
      {
        path: 'stu',
        name: 'stu',
        components: {
          right: stu,
        },
        meta: {
          title: '处方详情',
          isAuthenticated: false,
        },
      },
      {
        path: 'countdata',
        name: 'countdata',
        components: {
          right: countdata,
        },
        meta: {
          title: '计费',
          isAuthenticated: false,
        },
      },
      {
        path: 'Renshiguanli',
        name: 'Renshiguanli',
        components: {
          right: Renshiguanli,
        },
        meta: {
          title: '人事管理',
          isAuthenticated: false,
        },
      },
      {
        path: 'Family',
        name: 'Family',
        components: {
          right: Family,
        },
        meta: {
          title: '家族成员',
          isAuthenticated: false,
        },
      },

      {
        path: 'Xiangxixingxi',
        name: 'Xiangxixingxi',
        components: {
          right: xiangxixingxi,
        },
        meta: {
          title: '详细信息',
          isAuthenticated: false,
        },
      },
      {
        path: 'jiashu',
        name: 'jiashu',
        components: {
          right: jiashu,
        },
        meta: {
          title: '家属',
          isAuthenticated: false,
        },
      },
      {
        path: 'jianli',
        name: 'jianli',
        components: {
          right: jianli,
        },
        meta: {
          title: '简历',
          isAuthenticated: false,
        },
      },

      {
        path: 'Levelcode',
        name: 'Levelcode',
        components: {
          right: Levelcode,
        },
        meta: {
          title: '级别码',
          isAuthenticated: false,
        },
      },
      {
        path: 'Medicalmoney',
        name: 'Medicalmoney',
        components: {
          right: Medicalmoney,
        },
        meta: {
          title: '报销单',
          isAuthenticated: false,
        },
      },
      {
        path: 'Bill',
        name: 'Bill',
        components: {
          right: Bill,
        },
        meta: {
          title: '代扣计费',
          isAuthenticated: false,
        },
      },
      {
        path: 'Medical',
        name: 'Medical',
        components: {
          right: Medical,
        },
        meta: {
          title: '医疗卡信息',
          isAuthenticated: false,
        },
      },
      {
        path: 'Top-table',
        name: 'Top-table',
        components: {
          right: Toptable,
        },
        meta: {
          title: '充值账单',
          isAuthenticated: false,
        },
      },
      {
        path: 'Top-up',
        name: 'Top-up',
        components: {
          right: Topup,
        },
        meta: {
          title: '充值',
          isAuthenticated: false,
        },
      },
      {
        path: 'PatientsOther',
        name: 'PatientsOther',
        components: {
          right: PatientsOther,
        },
        meta: {
          title: '外校病人',
          isAuthenticated: false,
        },
      },
      {
        path: 'PatientsOur',
        name: 'PatientsOur',
        components: {
          right: PatientsOur,
        },
        meta: {
          title: '本校病人',
          isAuthenticated: false,
        },
      },
      {
        path: 'RegistrationDetials',
        name: 'RegistrationDetials',
        components: {
          right: RegistrationDetials,
        },
        meta: {
          title: '挂号详情',
          isAuthenticated: false,
        },
      },
      {
        path: 'Tongji',
        name: 'Tongji',
        components: {
          right: Tongji,
        },
        meta: {
          title: '挂号统计',
          isAuthenticated: false,
        },
      },
      {
        path: 'BinganXq',
        name: 'BinganXq',
        components: {
          right: BinganXq,
        },
        meta: {
          title: '病案详情',
          isAuthenticated: false,
        },
      },
      {
        path: 'Doctorviews',
        name: 'Doctorviews',
        components: {
          right: Doctorviews,
        },
        meta: {
          title: '医生信息',
          isAuthenticated: false,
        },
      },
      {
        path: 'Jianchaitems',
        name: 'Jianchaitems',
        components: {
          right: Jianchaitems,
        },
        meta: {
          title: '检查项目',
          isAuthenticated: false,
        },
      },
      {
        path: 'Menzhenkemu',
        name: 'Menzhenkemu',
        components: {
          right: Menzhenkemu,
        },
        meta: {
          title: '门诊科目',
          isAuthenticated: false,
        },
      },
      {
        path: 'Shujutongji',
        name: 'Shujutongji',
        components: {
          right: Shujutongji,
        },
        meta: {
          title: '数据统计',
          isAuthenticated: false,
        },
      },
      {
        path: 'Searchziliao',
        name: 'Searchziliao',
        components: {
          right: Searchziliao,
        },
        meta: {
          title: '资料查询',
          isAuthenticated: false,
        },
      },
      {
        path: 'bingan',
        name: 'bingan',
        components: {
          right: bingan,
        },
        meta: {
          title: '病案',
          isAuthenticated: false,
        },
      },
      {
        path: 'bingli',
        name: 'bingli',
        components: {
          right: bingli,
        },
        meta: {
          title: '病例',
          isAuthenticated: false,
        },
      },
      {
        path: 'guojijibing',
        name: 'guojijibing',
        components: {
          right: guojijibing,
        },
        meta: {
          title: '国际疫情',
          isAuthenticated: false,
        },
      },
      {
        path: 'shoushu',
        name: 'shoushu',
        components: {
          right: shoushu,
        },
        meta: {
          title: '手术详情',
          isAuthenticated: false,
        },
      },
      {
        path: 'Bingantongji',
        name: 'Bingantongji',
        components: {
          right: Bingantongji,
        },
        meta: {
          title: '病案统计',
          isAuthenticated: false,
        },
      },
      {
        path: 'UpdataBingAn',
        name: 'UpdataBingAn',
        components: {
          right: UpdataBingAn,
        },
        meta: {
          title: '修改病案',
          isAuthenticated: false,
        },
      },
    ],
  },
  {
    path: '/',
    redirect: 'Login',
  },
];

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
});

// router.beforeEach((to, from, next) => {
//   if (!sessionStorage.user) {
//     to.meta.isAuthenticated = false
//   } else {
//     to.meta.isAuthenticated = true
//   }
//   if (to.name !== 'Login' && !to.meta.isAuthenticated) next({ name: 'Login' })
//   next()
// })

export default router;
